package com.wc.alorithm_blue_bridge._数据结构.并查集.Q1135;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.StreamTokenizer;

/**
 * @Author congege
 * @Description
 * @Date Created in 2023/10/31-21:22
 */
public class Answer {
    static int[] circle;

    public static void main(String[] args) {
        Input sc = new Input();
        int n = sc.nextInt();
        int m = sc.nextInt();
        circle = new int[n + 1];
        String yes = "YES";
        String no = "NO";
        for (int i = 1; i <= n; i++) {
            circle[i] = i;
        }
        Answer answer = new Answer();
        StringBuffer ans = new StringBuffer();
        while (m-->0){
            int choose = sc.nextInt();
            int id1 = sc.nextInt();
            int id2 = sc.nextInt();
            if (choose==1){
                answer.merge(id1,id2);
            }else {
                if (answer.find(id1)== answer.find(id2)){
                    ans.append(yes);
                }else {
                    ans.append(no);
                }
                ans.append('\n');
            }
        }
        System.out.print(ans);
    }

    public int find(int id) {
        if (id == circle[id]) {
            return id;
        }
        return find(circle[id]);
    }

    public void merge(int id1, int id2) {
        int preId1 = find(id1);
        int preId2 = find(id2);
        if (preId1 != preId2) {
            circle[preId1] = preId2;
            // 上下均可
            // circle[preId1] = preId2;
            // circle[preId2] = preId1
        }
    }

    static class Input {
        StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));

        public int nextInt() {
            try {
                in.nextToken();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return (int) in.nval;
        }
    }
}
